package dual.activity;

import android.app.Activity;
import android.content.Intent;
import processing.core.PApplet;

public class ProcSketch extends PApplet {
	
	float oldX;
	float oldY;
	int gestInt = 0;
	
	@Override
	public boolean dragCanExit() {
	    // Prevent a downward drag from exiting the activity
	    // if the scroll view is showing and its content is
	    // not scrolled to the top.
	    return true;
	}
	
	public void setup() {
		
	}

	public void draw() {
	  if (mousePressed) {
	    fill(254,0,0);
	  } else {
	    fill(0,0,254);
	  }
	  ellipse(mouseX, mouseY, 20, 20);
	}

	public int sketchWidth() { return 160; }
	public int sketchHeight() { return 160; }
	
	public void mousePressed() {
		gestInt = 0;
		oldY = mouseY;
		oldX = mouseX;
		//System.out.println("pressed " + mouseY);
	}
	
	public void mouseDragged() {
		if (gestInt >= 0){
			if (mouseX-oldX < 10 && mouseX-oldX > -10){
				if (mouseY-oldY>50) {
					gestInt = 1;
				}
			}
			else {
				gestInt = -1;
			}
		}

		//System.out.println("dragged " + mouseY);
	}

	public void mouseReleased() {
		if (gestInt == 1){
			gestInt = 0;
			leave();
		}
	}
	
	public void leave(){
	    Intent intent = new Intent();
	    intent.putExtra("test", "foo");
	    setResult(Activity.RESULT_FIRST_USER, intent);
	    finish();   
	}

}
